<?php
/**
 * Search.php
 * Created by PhpStorm.
 * User: 江小波
 * Date: 2019/06/14
 * Time: 13:20
 */
namespace app\api\open\member\order;

use app\api\open\member\Token;
use app\api\open\Base;
use app\api\model\OrderModel;
use app\common\Singleton;

class Search extends Token
{
    protected $where = [];

    public function __construct($param = [])
    {
        try{
            parent::__construct($param);
        }catch (\Exception $e) {
            $this->member_id = null;
            $this->token_data = [];
        }
		// 订单状态（0待确认, 1已确认/待支付, 2已支付/待发货, 3已发货/待收货, 4已完成, 5已取消, 6已关闭）
		if(isset($this->params['status']) && $this->params['status']!='')
		{
			$this->where['status'] = $this->params['status'];
		}
		// 支付状态（0未支付, 1已支付, 2已退款）
		if(isset($this->params['pay_status']) && $this->params['pay_status']!='')
		{
			$this->where['pay_status'] = $this->params['pay_status'];
		}
		// 会员ID
		if(isset($this->params['member_id']) && $this->params['member_id']!='')
		{
			$this->where['member_id'] = $this->params['member_id'];
		}
		// 商店id
		if(isset($this->params['store_id']) && $this->params['store_id']!='')
		{
			$this->where['store_id'] = $this->params['store_id'];
		}
		// 供应商id
		if(isset($this->params['supplier_id']) && $this->params['supplier_id']!='')
		{
			$this->where['supplier_id'] = $this->params['supplier_id'];
		}
		// 收件地址id
		if(isset($this->params['receive_address_id']) && $this->params['receive_address_id']!='')
		{
			$this->where['receive_address_id'] = $this->params['receive_address_id'];
		}
		// 收件人-省
		if(isset($this->params['receive_province']) && $this->params['receive_province']!='')
		{
			$this->where['receive_province'] = $this->params['receive_province'];
		}
		// 收件人-市
		if(isset($this->params['receive_city']) && $this->params['receive_city']!='')
		{
			$this->where['receive_city'] = $this->params['receive_city'];
		}
		// 收件人-县/区
		if(isset($this->params['receive_county']) && $this->params['receive_county']!='')
		{
			$this->where['receive_county'] = $this->params['receive_county'];
		}
		// 快递id
		if(isset($this->params['express_id']) && $this->params['express_id']!='')
		{
			$this->where['express_id'] = $this->params['express_id'];
		}
		// 支付方式id
		if(isset($this->params['payment_id']) && $this->params['payment_id']!='')
		{
			$this->where['payment_id'] = $this->params['payment_id'];
		}
		// 支付时间
		if(isset($this->params['pay_time']) && $this->params['pay_time']!='')
		{
			$this->where['pay_time'] = $this->params['pay_time'];
		}
		// 确认时间
		if(isset($this->params['confirm_time']) && $this->params['confirm_time']!='')
		{
			$this->where['confirm_time'] = $this->params['confirm_time'];
		}
		// 发货时间
		if(isset($this->params['delivery_time']) && $this->params['delivery_time']!='')
		{
			$this->where['delivery_time'] = $this->params['delivery_time'];
		}
		// 取消时间
		if(isset($this->params['cancel_time']) && $this->params['cancel_time']!='')
		{
			$this->where['cancel_time'] = $this->params['cancel_time'];
		}
		// 收货时间
		if(isset($this->params['collect_time']) && $this->params['collect_time']!='')
		{
			$this->where['collect_time'] = $this->params['collect_time'];
		}
		// 关闭时间
		if(isset($this->params['close_time']) && $this->params['close_time']!='')
		{
			$this->where['close_time'] = $this->params['close_time'];
		}
		// 商家是否已评论（0否, 大于0评论时间）
		if(isset($this->params['is_comments']) && $this->params['is_comments']!='')
		{
			$this->where['is_comments'] = $this->params['is_comments'];
		}
		// 用户是否已评论（0否, 大于0评论时间）
		if(isset($this->params['member_is_comments']) && $this->params['member_is_comments']!='')
		{
			$this->where['member_is_comments'] = $this->params['member_is_comments'];
		}
		// 商家是否已删除（0否, 大于0删除时间）
		if(isset($this->params['is_delete_time']) && $this->params['is_delete_time']!='')
		{
			$this->where['is_delete_time'] = $this->params['is_delete_time'];
		}
		// 用户是否已删除（0否, 大于0删除时间）
		if(isset($this->params['member_is_delete_time']) && $this->params['member_is_delete_time']!='')
		{
			$this->where['member_is_delete_time'] = $this->params['member_is_delete_time'];
		}
		// 增加的金额
		if(isset($this->params['increase_price']) && $this->params['increase_price']!='')
		{
			$this->where['increase_price'] = $this->params['increase_price'];
		}
		// 优惠金额
		if(isset($this->params['preferential_price']) && $this->params['preferential_price']!='')
		{
			$this->where['preferential_price'] = $this->params['preferential_price'];
		}
		// 订单单价
		if(isset($this->params['price']) && $this->params['price']!='')
		{
			$this->where['price'] = $this->params['price'];
		}
		// 订单总价(订单最终价格)
		if(isset($this->params['total_price']) && $this->params['total_price']!='')
		{
			$this->where['total_price'] = $this->params['total_price'];
		}
		// 已支付金额
		if(isset($this->params['pay_price']) && $this->params['pay_price']!='')
		{
			$this->where['pay_price'] = $this->params['pay_price'];
		}
		// 收件人-电话
		if(isset($this->params['receive_tel']) && $this->params['receive_tel']!='')
		{
			$this->where['receive_tel'] = $this->params['receive_tel'];
		}
		// 订单号
		if(isset($this->params['order_no']) && $this->params['order_no']!='')
		{
			$this->where['order_no'] = $this->params['order_no'];
		}
		// 收件人-姓名
		if(isset($this->params['receive_name']) && $this->params['receive_name']!='')
		{
			$this->where['receive_name'] = $this->params['receive_name'];
		}
		// 收件人-详细地址
		if(isset($this->params['receive_address']) && $this->params['receive_address']!='')
		{
			$this->where['receive_address'] = $this->params['receive_address'];
		}
		// 用户备注
		if(isset($this->params['member_note']) && $this->params['member_note']!='')
		{
			$this->where['member_note'] = $this->params['member_note'];
		}
		// 快递单号
		if(isset($this->params['express_number']) && $this->params['express_number']!='')
		{
			$this->where['express_number'] = $this->params['express_number'];
		}
		// 扩展展示数据
		if(isset($this->params['extension_data']) && $this->params['extension_data']!='')
		{
			$this->where['extension_data'] = $this->params['extension_data'];
		}
    }
    
    /**
     * @param array $param
     * @return array|false|null|\PDOStatement|string|\think\Model
     * @throws \Exception
     */
    public function index($param=[])
    {
        // 获取列表
        return OrderModel::getInstance()->getList($this->where,[
            'field'=> '*'
        ]);
    }
}